<?php

/**

 * cms 信息|单页内容接口

 * @author maniac

 */

namespace app\api\controller\v1;
use app\facade\Contents as ContentsFacade;
use app\facade\Options AS OptionsFacade;



class Contents extends Base

{

    /**

     * 获取内容

     */


    public function contents()
    {
        try {
            $post     = input('post.');
            $contents = query_contents($post);
            if(isset($post['column_id'])){
                foreach($contents as $k=>$v){
                    $contents[$k]['titlepic_url']=attach_uri($v['titlepic']);
                }
            }

            if(isset($post['id'])){
                if($contents['titlepic']>0){
                    $contents['titlepic_url']=attach_uri($contents['titlepic']);
                }


                $options = unserialize(OptionsFacade::option('site_info'));
                $url=$options['site_url'];

                $contents['vice_data']['content']=preg_replace('/<img src="([\w\W]*?)"/', '<img src="'.$url.'${1}"', stripslashes($contents['vice_data']['content']));
            }

            return j(0, '获取数据成功', $contents);

        } catch (\Exception $e) {

            exception($e->getMessage());

        }

    }

	/*
	 * 获取论文视频等详情
	 *
	 * */
	public function getInfo(){
		$userToken = input('userToken','');
		$userId = 0;
		if($userToken){
			$userId = $this->checkUserToken();
		}

		try {
			$id     = input('id',0);//视频论文等ID

			$info = ContentsFacade::getInfo($userId,$id);

			return j(0, '获取数据成功', $info);

		} catch (\Exception $e) {

			return j(1, $e->getMessage());

		}
	}

}

